<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>用户管理</title>
    <meta name="keywords" content="">
    <link href="../resources/bootstrap/css/bootstrap-huan.css" rel="stylesheet">
    <link href="../resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../resources/css/style.css" rel="stylesheet">

    <link href="../resources/css/exam.css" rel="stylesheet">
    <!-- Javascript files -->
    <!-- jQuery -->
    <script type="text/javascript" src="../resources/js/jquery/jquery-1.9.0.min.js"></script>
    <!-- Bootstrap JS -->
    <script type="text/javascript" src="../resources/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../resources/js/all.js"></script>
    <script type="text/javascript" src="../resources/js/register.js"></script>
    <style type="text/css">
        .form-group {
            margin-bottom: 5px;
            height: 59px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div class="lrform">
                <span class="form-message"></span>
                <div class="form">
                    <!-- Register form (not working)-->
                    <form class="form-horizontal" id="form-create-account">
                        <div class="form-line form-username" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>用户名：</span>
                            <input type="text" class="df-input-narrow" id="username" maxlength="20"
                                   style="width: 200px;">
                            <span class="form-message"></span> <br>
                        </div>
                        <div class="form-line form-password" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>密码：</span>
                            <input type="password" class="df-input-narrow" id="password" maxlength="20"
                                   style="width: 200px;">
                            <span class="form-message"></span> <br>
                        </div>
                        <div class="form-line form-truename" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>真实姓名：</span>
                            <input type="text" class="df-input-narrow" id="truename" maxlength="20"
                                   style="width: 200px;">
                            <span class="form-message"></span> <br>
                        </div>
                        <div class="form-line form-national-id" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>身份证号：</span>
                            <input type="text" class="df-input-narrow" id="cardId" maxlength="18" style="width: 200px;">
                            <span class="form-message"></span> <br>
                        </div>
                        <div class="form-line form-phone" style="display: block;">
                            <span class="form-label">手机：</span>
                            <input type="text" class="df-input-narrow" id="phone" maxlength="18" style="width: 200px;">
                            <span class="form-message"></span> <br>
                        </div>
                        <div class="form-line form-email" style="display: block;">
                            <span class="form-label"><span class="warning-label">*</span>邮箱：</span>
                            <input type="text" class="df-input-narrow" id="email" maxlength="60" style="width: 200px;">
                            <span class="form-message"></span> <br>
                        </div>
                        <div class="form-line" style="display: block;">
                            <span class="form-label"><span class="warning-label"></span>班级：</span>
                            <select id="department" class="df-input-narrow">
                                <option value="-1">--请选择--</option>
                            </select>
                            <span class="form-message"></span> <br>
                        </div>
                        <div class="form-group">
                            <div class="col-md-9 col-md-offset-3">
                                <button type="button" class="btn btn-info" id="btn-add">确定添加</button>
                                <button type="reset" class="btn btn-info">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>

</div>
</body>
</html>
<script>

    var getAllDep = function () {
        $.ajax({
            type: "POST",
            url: "/getAllDep",
            dataType: "JSON",
            success: function (data) {
                //console.log(data);
                $(".deps").remove();
                $.each(data, function (idx, obj) {
                    var v = "<option class='deps' value='" + obj.depId + "'>" + obj.depName + "</option>";
                    $("#department").append(v);
                });
            }
        });
    };

    getAllDep();

    $("#btn-add").click(function () {
        addUser();
    });

    var addUser = function () {
        $.ajax({
            type: "POST",
            url: "/addUser",
            data: {
                userName: $("#username").val(),
                trueName: $("#truename").val(),
                nationalId: $("#cardId").val(),
                password: $("#password").val(),
                email: $("#email").val(),
                phoneNum: $("#phone").val(),
                createBy: 1,
                enabled: 1,
                fieldId: 0,
                depId: $("#department").val()
            },
            success: function (data) {
                if (data == "success") {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.getUserByPage();
                    parent.layer.close(index);
                }
            }

        });
    };

</script>